package com.qf.controller;


import com.qf.pojo.Recycle;
import com.qf.service.RecycleService;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/recycle")
@CrossOrigin
public class RecycleController {

    @Autowired
    RecycleService recycleService;

    @GetMapping("/findAll")
    public ResultMsg findAll(@RequestParam(required = false, defaultValue = "1")int current,@RequestParam(required = false, defaultValue = "20")int pageSize){
        return  recycleService.findAll(current,pageSize);
    }

    @GetMapping("/findOne")
    public ResultMsg findOne(int recycleId){
        return  recycleService.findOne(recycleId);
    }

    @GetMapping("/findAllByDate")
    public ResultMsg findAllByDate(String startTime, String endTime,@RequestParam(required = false, defaultValue = "1")Integer current, @RequestParam(required = false, defaultValue = "20")Integer pageSize){
        return  recycleService.findAllByDate(startTime,endTime,current,pageSize);
    }

    @PostMapping("/add")
    public ResultMsg add(@RequestBody Recycle recycle){
        return recycleService.add(recycle);
    }

    @PostMapping("/updateRecycle")
    public ResultMsg updateRecycle(@RequestBody Recycle recycle){
        return recycleService.updateRecycle(recycle);
    }

    @PostMapping("/deleteRecycle")
    public ResultMsg delRecycle(@RequestBody Map<String,Object> map){
        return recycleService.delRecycle(map);
    }

}
